package com.lc.railway.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.railway.R;
import com.lc.railway.http.glide.GlideApp;
import com.lc.railway.http.request.ApiProductLinkApi;
import com.lc.railway.http.response.ProductLinkBean;
import com.lc.railway.ui.dialog.FieldsDialog;

import org.jetbrains.annotations.NotNull;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 友情链接
 */
public class LinksActivity extends WaterActivity {
    @BindView(R.id.title_bar_top)
    TitleBar titleBarTop;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private BaseQuickAdapter<ProductLinkBean.DataBean, BaseViewHolder> adapter;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_links;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        titleBarTop.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {

            }

            @Override
            public void onRightClick(View v) {
                FieldsDialog dialog=new FieldsDialog(getContext(),LinksActivity.this,"友情链接");
                dialog.show();
            }
        });
        recyclerView.setLayoutManager(new GridLayoutManager(this,2));
       adapter=new BaseQuickAdapter<ProductLinkBean.DataBean, BaseViewHolder>(R.layout.item_links) {
            @Override
            protected void convert(@NotNull BaseViewHolder holder, ProductLinkBean.DataBean s) {
                GlideApp.with(getContext()).load(s.getPicurl()).error(R.drawable.image11).into(((ImageView) holder.getView(R.id.img_logo)));

            }
        };
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {

            }
        });
        api_news_lists();
    }
    private void api_news_lists() {
        EasyHttp.post(this)
                .api(new ApiProductLinkApi())
                .request(new HttpCallback<ProductLinkBean>(this) {
                    @Override
                    public void onSucceed(ProductLinkBean data) {

                        if (data.getError_code() == 200) {
                          adapter.setNewData(data.getData());

                        }
                    }
                });


    }
}
